<?php 
require_once("../include/connect.php");
class events {

function eventslist(){
	$adjacents = 3;
	$adjacents = 3;
	$query = "select events.id,events.name,events.description, events.note, events.cost, events.isactive, event_detail.startdate, event_detail.starttime, event_detail.enddate, event_detail.endtime,event_detail.placeid from events inner join event_detail on events.id = event_detail.eventid where events.isdeleted = 0 and event_detail.isdeleted = 0";
	//$total_pages = mysql_fetch_array(mysql_query($query));
	$total_pages = mysql_num_rows(mysql_query($query));
	
	$targetpage = "user.php";
	$limit = 5;
	$page = $_GET['page'];
	if($page) 
		$start = ($page - 1) * $limit;
	else
		$start = 0;
    $sql = "select events.id,events.name,events.description, events.note, events.cost, events.isactive, event_detail.startdate, event_detail.starttime, event_detail.enddate, event_detail.endtime,event_detail.placeid from events inner join event_detail on events.id = event_detail.eventid where events.isdeleted = 0 and event_detail.isdeleted = 0 LIMIT $start, $limit";
	$result = mysql_query($sql);
	
	echo "<div id=\"innerContent\">
    <div id=\"listHeader\">
      <p class=\"listInfos\">". $total_pages ." adet Kayit bulundu. </p>
    </div>
    <table cellspacing=\"0\" class=\"listTable\" id=\"postList\">
      <thead>
        <tr>
          <th class=\"first\"><div><a href=\"#\" title=\"id\">id</a><div></th>
          <th><a href=\"#\" title=\"usergroupid\">Etkinlik Adı</a></th>
          <th><a href=\"#\" title=\"firstname\">Açıkalama</a></th>
          <th><a href=\"#\" title=\"email\">Ücretler</a></th>
		  <th><a href=\"#\" title=\"gender\">Durum</a></th>
		  <th><a href=\"#\" title=\"isapproved\">B.Tarih</a></th>
		  <th><a href=\"#\" title=\"jobid\">Bit.Tar.</a></th>
		  <th><a href=\"#\" title=\"jobid\">Mekanid</a></th>
		  <th class=\"last\"><a href=\"#\" title=\"actions\">Islemler</a></th>
        </tr>
      </thead>
	  <tfoot>
		  <tr>
		  <td colspan=\"9\">
              <div class=\"inner\">
                <div class=\"paginate\">";
	if ($page == 0) $page = 1;					
	$prev = $page - 1;							
	$next = $page + 1;							
	$lastpage = ceil($total_pages/$limit);		
	$lpm1 = $lastpage - 1;						
	
	$pagination = "";
	if($lastpage > 1)
	{	
		//previous button
		if ($page > 1) 
			echo  "<span class=\"prev\"><a href=\"$targetpage?page=$prev\">&lt;&lt; &#246;nceki</a></span>";
		else
			echo  "<span class=\"prev disabled\">&lt;&lt; &#246;nceki</span>";	
		
		//pages	
		if ($lastpage < 7 + ($adjacents * 2))	//not enough pages to bother breaking it up
		{	
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page)
					echo  "<span class=\"current roundedBordersLite\">$counter</span>";
				else
					echo  "<span class=\"current roundedBordersLite\"><a href=\"$targetpage?page=$counter\">$counter</a></span>";					
			}
		}
		elseif($lastpage > 5 + ($adjacents * 2))	//enough pages to hide some
		{
			//close to beginning; only hide later pages
			if($page < 1 + ($adjacents * 2))		
			{
				for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
				{
					if ($counter == $page)
						echo  "<span class=\"current roundedBordersLite\">$counter</span>";
					else
						echo  "<span class=\"current roundedBordersLite\"><a href=\"$targetpage?page=$counter\">$counter</a></span>";					
				}
				echo  "...";
				echo  "<span class=\"next\"><a href=\"$targetpage?page=$lpm1\">$lpm1</a></span>";
				echo  "<span class=\"next\"><a href=\"$targetpage?page=$lastpage\">$lastpage</a></span>";		
			}
			//in middle; hide some front and some back
			elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
			{
				echo  "<span class=\"next\"><a href=\"$targetpage?page=1\">1</a></span>";
				echo  "<span class=\"next\"><a href=\"$targetpage?page=2\">2</a></span>";
				echo  "...";
				for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
				{
					if ($counter == $page)
						echo  "<span class=\"current roundedBordersLite\">$counter</span>";
					else
						echo  "<span class=\"current roundedBordersLite\"><a href=\"$targetpage?page=$counter\">$counter</a></span>";					
				}
				echo  "...";
				echo  "<span class=\"next\"><a href=\"$targetpage?page=$lpm1\">$lpm1</a></span>";
				echo  "<span class=\"next\"><a href=\"$targetpage?page=$lastpage\">$lastpage</a></span>";		
			}
			//close to end; only hide early pages
			else
			{
				echo  "<span class=\"next\"><a href=\"$targetpage?page=1\">1</a></span>";
				echo  "<span class=\"next\"><a href=\"$targetpage?page=2\">2</a></span>";
				echo  "...";
				for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
				{
					if ($counter == $page)
						echo  "<span class=\"current roundedBordersLite\">$counter</span>";
					else
						echo  "<span class=\"current roundedBordersLite\"><a href=\"$targetpage?page=$counter\">$counter</a></span>";					
				}
			}
		}
		
		//next button
		if ($page < $counter - 1) 
			echo  "<span class=\"next\"><a href=\"$targetpage?page=$next\">ileri »</a></span>";
		else
			echo  "<span class=\"next disabled\">ileri »</span>";
				
	}
	echo  "</div>
		      </div>
          </td>
        </tr>
      </tfoot>\n";
      echo "<tbody>";
        while($row = mysql_fetch_array($result))
		{
		   echo "<tr>";
		   echo "<td><div>".$row["id"]."</div></td>";
		   echo "<td><div>".$row["name"]."</div></td>";
		   echo "<td><div>".$row["description"]."</div></td>";
		   //echo "<td><div>".$row["note"]."</div></td>";
		   echo "<td><div>".$row["cost"]."</div></td>";
		   echo "<td><div>".$row["isactive"]."</div></td>";
		   echo "<td><div>".$row["startdate"]. " ".$row["starttime"]."</div></td>";
		   echo "<td><div>".$row["enddate"]. " ".$row["endtime"]."</div></td>";
		   echo "<td><div>".$row["placeid"]."</div></td>";
		   echo "<td><div><a href=\"#\">Onayla</a><a href=\"#\">Sil</a><a href=\"#\">D&uuml;zenle</a><a href=\"#\">Detaylar</a></div></td>";
		   echo "</tr>";
		}
		echo "</tbody>
    </table>
  </div>";
	}
}
$events = new events();
?>